import axios from 'axios';

export default function (callback, params) {
	// 暴露出封装好的axios方法，方便接口的统一规划
	var setting = params.setting;
	if(typeof setting !== 'object') {
		var req = {
			reason: '请求错误',
			status: 888,
			data: null
		};
		return callback(req);
	}
	return axios({
		method: setting.method || 'GET',
		baseURL: 'http://47.92.216.173:80/YF/public/api',
		timeout: 1000*10,
		url: setting.url || '',
		data: params.data ? params.data : null,
		contentType: setting.contentType ? setting.contentType : null,
		headers: setting.headers ? setting.headers : null
	}).then(
		function (res) {
			var status = res.data.status;
			res = res.data;
			callback(res);
		}.bind(this),
		function (res) {
			var req = {
				reason: '网络错误',
				status: 999,
				data: null
			};
			callback(req);
		}.bind(this)
	);
}